﻿using System;
using System.Web.UI.WebControls;
using ASPNETVN.PORTAL.Components.UI;
using ASPNETVN.PORTAL.Components.Configuration.Settings;
using ASPNETVN.PORTAL.Components.UI.DataTypes;
using System.Collections;

namespace ThoiTiet.Modules.ProvinceWeather
{
    public enum ModulePages
    {
        CurrentWeather,
        DetailProvinceWeather,
        ProvinceWeather
    }

    public partial class Main : PortalModuleControl
    {
        public Main()
        {
            // Define an Array List
            ArrayList list = new ArrayList();
            list.Add(new ListItem("CurrentWeather", "CurrentWeather"));
            list.Add(new ListItem("DetailProvinceWeather", "DetailProvinceWeather"));
            list.Add(new ListItem("ProvinceWeather", "ProvinceWeather"));

            ModuleSettingItem itemSetting = new ModuleSettingItem(new CustomListDataType(list, "Text", "Value"));
            itemSetting.Value = "AreasWeather";
            itemSetting.Name = "Hình thức hiển thị nội dung";
            itemSetting.Description = "Hình thức hiển thị nội dung";
            itemSetting.SortOrder = 1;
            this.BaseSettings.Add("DisplayStyle", itemSetting);

            itemSetting = new ModuleSettingItem(new StringDataType());
            itemSetting.Value = "";
            itemSetting.Name = "Đường dẫn của file flash (*.swf)";
            itemSetting.Description = "Đường dẫn của file flash (*.swf)";
            itemSetting.SortOrder = 2;
            this.BaseSettings.Add("PathFlash", itemSetting);
        }

        private void LoadChildControl()
        {
            const string basePath = "~/Modules/ThoiTiet.Modules.ProvinceWeather/";
            ModulePages page = (ModulePages)Enum.Parse(typeof(ModulePages), this.Settings["DisplayStyle"].ToString(), true);            
            string src = string.Format("{0}Controls/{1}.ascx", basePath, page);
            ModulePage ctl = (ModulePage)this.LoadControl(src);
            ctl.ParentControl = this;
            ContentPane.Controls.Add(ctl);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.LoadChildControl();
        }
    }
}